import {getContainerSources, getStorageSources, WORKSTATE, workSwitch} from "./public/CreepPublicAction.js";

export const ghodiumTransporterRun = (creep, sourcesIndex) => {
    workSwitch(creep, RESOURCE_GHODIUM)
    if (creep.memory[WORKSTATE]) {
        workCore(creep)
    } else {
        getSources(creep)
    }
}

const workCore = (creep) => {
    if (creep.generateSafeMode(creep.room.controller) === ERR_NOT_IN_RANGE) {
        creep.moveTo(creep.room.controller);
        // console.log(Memory.Rooms[creep.room.name].path.spawnToController)
        // creep.moveByPath(Room.deserializePath(Memory.Rooms[creep.room.name].path.spawnToController))
    }
}

const getSources = (creep) => {
    const terminal = creep.room.terminal
    //存在terminal时且其中能量大于10000则从terminal中取能量
    if (terminal && terminal.store[RESOURCE_GHODIUM] >= 1000) {
        if (creep.withdraw(terminal, RESOURCE_GHODIUM) === ERR_NOT_IN_RANGE) {
            creep.moveTo(terminal)
        }
    }
}